<?php
# Sample that explains you how to use the PHP RawsClient lib to communicate with the RAMS 'total' resource
#
# Copyright (C) 2010 rambla.be

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_once '../RawsClient/Raws/Rams.php';

# Provide your own credentials here
define('BASE', 'http://rams.mon01.rambla.be/');
define('USER', 'XXX');
define('PWD', 'XXX');

try {
  $rams = new Rams(USER, PWD, BASE);

  echo "->Retrieving a RAMS Total Feed:\n";
  # Pass a Query-String to limit the feed elements to files only
  $query = new Rams_TotalQuery();
  $query->setYear("2010");
  $query->setMonth("11");
  # get the feed
  $feed = $rams->getTotalFeed($query);
  foreach ($feed as $entry) {
    # Retrieve the entry element's "type" attribute
    echo "Found " . $entry->type . " entry \n";
    # Retrieve the value of the params child elements
    echo "Unique: " . $entry->content->params->unique->text . "\n";
    echo "Hits: " . $entry->content->params->hits->text . "\n";
    echo "Events: " . $entry->content->params->events->text . "\n";
    echo "Volume: " . $entry->content->params->volume->text . "\n";
    echo "Last Modified: " . $entry->content->params->last_modified->text . "\n";
    echo "\n";
  }

  
}
catch(Zend_Gdata_App_Exception $e) {
    # Report the exception to the user
    echo "\nCaught exception: " . get_class($e) . "\n";
    echo "Message: " . $e->getMessage() . "\n";
    # get the HTTP status code
    echo "HTTP Status Code: " . $e->getResponse()->getStatus() . "\n";
    echo "Response Body with exception details: " . $e->getResponse()->getBody() . "\n";
    # get the raws:error elements
    $rawsResponse = Raws::parseRawsResponse($e->getResponse());
    echo "Raws Code: " . $rawsResponse->getCode() . "\n";
    echo "Raws Message: " . $rawsResponse->getMsg() . "\n";
    $reasons = $rawsResponse->getReasons();
    foreach ($reasons as $reason) {
      echo "Raws Reason: " . $reason . "\n";
    }
    $details = $rawsResponse->getDetails();
    foreach ($details as $key => $value) {
      echo "Raws Detail: " . $key . " -> " . $value . "\n";
    }
}
catch (Zend_Exception $e) {
    echo "Caught exception: " . get_class($e) . "\n";
    echo "Message: " . $e->getMessage() . "\n";
}
